package com.sgb.kjwl.view.ui.adapter.search;

import android.content.Context;
import android.graphics.Paint;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.TextUtils;
import android.text.style.StrikethroughSpan;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.sgb.kjwl.BR;
import com.sgb.kjwl.R;
import com.sgb.kjwl.model.entity.SearchMaterialEntity3;
import com.sgb.kjwl.view.ui.activity.manage.ShopInfoForCompanyTradesActivity;
import com.sgb.kjwl.view.ui.activity.packers.PackersProjectTeamActivity;
import com.sgb.kjwl.view.ui.activity.self.shop.ShopInfoActivity;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;

import java.util.List;

public class SearchMaterialAdapter3 extends BaseRecycleAdapter<SearchMaterialEntity3> {

    private TextView contentView;
    private TextView cuPrice;
    private TextView brand;
    private TextView arrowView;
    private TextView tvSpec;
    private ImageView img_cx;

    public SearchMaterialAdapter3(Context context, List<SearchMaterialEntity3> datas) {
        super(context, R.layout.item_search_material3, datas);
    }

    @Override
    public void convert(ItemViewHolder holder, final SearchMaterialEntity3 entity) {
        holder.setBinding(BR.viewModel, entity);
        contentView = holder.getItem().findViewById(R.id.content_view);
        brand = holder.getItem().findViewById(R.id.brand);
        img_cx = holder.getItem().findViewById(R.id.img_cx);
        cuPrice = holder.getItem().findViewById(R.id.cu_price);
        TextView  priceView = holder.getItem().findViewById(R.id.price_view);
        tvSpec = holder.getItem().findViewById(R.id.tv_spec);
        arrowView = holder.getItem().findViewById(R.id.arrow_view);
        contentView.setText(entity.getCityName() + entity.getAreaName());
        priceView.setText("￥" + entity.getPrice() + "/" + entity.getUnit());
        if (TextUtils.isEmpty(entity.getBranName())) {
            brand.setVisibility(View.GONE);
        }
        if (entity.getPromoteStatus() == 2) {
            img_cx.setVisibility(View.VISIBLE);
            cuPrice.setVisibility(View.VISIBLE);
            tvSpec.setVisibility(View.VISIBLE);
            cuPrice.setText("￥" + entity.getPromotePrice() + "/" + entity.getUnit());
            cuPrice.setTextColor(context.getResources().getColor(R.color.new_org));
            priceView.setTextColor(context.getResources().getColor(R.color.color_666666));
            priceView.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG | Paint.ANTI_ALIAS_FLAG);
        } else {
            img_cx.setVisibility(View.GONE);
            cuPrice.setVisibility(View.GONE);
            tvSpec.setVisibility(View.GONE);
            priceView.setTextColor(context.getResources().getColor(R.color.new_org2));
            priceView.getPaint().setFlags(priceView.getPaintFlags() & (~Paint.STRIKE_THRU_TEXT_FLAG));
        }
        arrowView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                ShopInfoActivity.start(context, entity.getShopId());
                ShopInfoForCompanyTradesActivity.startAct(context, entity.getShopId(), "", 0, 0);
            }
        });
    }

}
